import MyRequest from '@/utils/request/index'

class Cart {
  getNewCartGoods = (skuId) => {
    return MyRequest.get({
      url: `/goods/stock/${skuId}`
    })
  }

  getGoodsSku = (skuId) => {
    return MyRequest.get({
      url: `/goods/sku/${skuId}`
    })
  }

  mergeCart = (cartList) => {
    return MyRequest.post({
      url: '/member/cart/merge',
      data: cartList
    })
  }

  findCart = () => {
    return MyRequest.get({
      url: '/member/cart'
    })
  }

  insertCart = ({ skuId, count }) => {
    return MyRequest.post({
      url: '/member/cart',
      data: { skuId, count }
    })
  }

  deleteCart = (ids) => {
    return MyRequest.delete({
      url: '/member/cart',
      data: { ids }
    })
  }

  updateCart = ({ skuId, selected, count }) => {
    return MyRequest.put({
      url: `/member/cart/${skuId}`,
      data: {
        selected,
        count
      }
    })
  }

  checkAllCart = ({ selected, ids }) => {
    return MyRequest.put({
      url: '/member/cart/selected',
      data: { selected, ids }
    })
  }
}

export default new Cart()
